package de.bht.netviz.ipsaver.lookup.model;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Strict XML binding of the GeoPlugin XML return.
 * 
 * @author Marius Hentschel
 * @since  2012/10/24
 */
@Entity
@Table(name="LOOKUPDATA", schema="DATA" )
@XmlRootElement(name="geoPlugin")
public class GeoPluginLookupData implements ILookupData {
   
   private long id;
   
	private String areaCode;
   private String continentCode;
   private String regionCode;
	private String currencyCode;
	private String currencySymbol;

   private String city;
   private String countryCode;
   private String countryName;
   private String ip;
   private String lat;
   private String lon;
   private String regionName;
   
//	private String geoplugin_status;
//	private String geoplugin_region;
//	private String geoplugin_dmaCode;
//	private String geoplugin_currencyConverter;

   public GeoPluginLookupData() {
   }

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public long getId() {
      return id;
   }

   @XmlElement(name = "geoplugin_city")
   @Override
   public String getCity() {
      return this.city;
   }

   @XmlElement(name = "geoplugin_countryCode")
   @Transient
   @Override
   public String getCountryCode() {
      return this.countryCode;
   }

   @XmlElement(name = "geoplugin_countryName")
   @Override
   public String getCountryName() {
      return this.countryName;
   }

   @XmlElement(name = "geoplugin_request")
   @Override
   public String getIp() {
      return this.ip;
   }

   @XmlElement(name = "geoplugin_latitude")
   @Override
   public String getLat() {
      return this.lat;
   }

   @XmlElement(name = "geoplugin_longitude")
   @Override
   public String getLon() {
      return this.lon;
   }

   @XmlElement(name = "geoplugin_regionName")
   @Override
   public String getRegionName() {
      return this.regionName;
   }
   
   @XmlElement(name="geoplugin_areaCode")
   @Transient
   public String getAreaCode() {
      return areaCode;
   }

   public void setAreaCode(String geoplugin_areaCode) {
      this.areaCode = geoplugin_areaCode;
   }

   @XmlElement(name="geoplugin_continentCode")
   @Transient
   public String getContinentCode() {
      return continentCode;
   }

   public void setContinentCode(String geoplugin_continentCode) {
      this.continentCode = geoplugin_continentCode;
   }

   @XmlElement(name="geoplugin_regionCode")
   @Transient
   public String getRegionCode() {
      return regionCode;
   }

   public void setRegionCode(String geoplugin_regionCode) {
      this.regionCode = geoplugin_regionCode;
   }

   @XmlElement(name="geoplugin_currencyCode")
   @Transient
   public String getCurrencyCode() {
      return currencyCode;
   }

   public void setCurrencyCode(String geoplugin_currencyCode) {
      this.currencyCode = geoplugin_currencyCode;
   }

   @XmlElement(name="geoplugin_currencySymbol")
   @Transient
   public String getCurrencySymbol() {
      return currencySymbol;
   }

   public void setCurrencySymbol(String geoplugin_currencySymbol) {
      this.currencySymbol = geoplugin_currencySymbol;
   }

   public void setId(long id) {
      this.id = id;
   }
   
   public void setCity(String city) {
      this.city = city;
   }

   public void setCountryCode(String countryCode) {
      this.countryCode = countryCode;
   }

   public void setCountryName(String countryName) {
      this.countryName = countryName;
   }

   public void setIp(String ip) {
      this.ip = ip;
   }

   public void setLat(String lat) {
      this.lat = lat;
   }

   public void setLon(String lon) {
      this.lon = lon;
   }

   public void setRegionName(String regionName) {
      this.regionName = regionName;
   }

   @Override
   public int hashCode() {
      int hash = 7;
      hash = 23 * hash + (int) (this.id ^ (this.id >>> 32));
      hash = 23 * hash + Objects.hashCode(this.city);
      hash = 23 * hash + Objects.hashCode(this.countryName);
      hash = 23 * hash + Objects.hashCode(this.ip);
      hash = 23 * hash + Objects.hashCode(this.lat);
      hash = 23 * hash + Objects.hashCode(this.lon);
      hash = 23 * hash + Objects.hashCode(this.regionName);
      return hash;
   }

   @Override
   public boolean equals(Object obj) {
      if (obj == null) {
         return false;
      }
      if (getClass() != obj.getClass()) {
         return false;
      }
      final GeoPluginLookupData other = (GeoPluginLookupData) obj;
      if (this.id != other.id) {
         return false;
      }
      if (!Objects.equals(this.city, other.city)) {
         return false;
      }
      if (!Objects.equals(this.countryName, other.countryName)) {
         return false;
      }
      if (!Objects.equals(this.ip, other.ip)) {
         return false;
      }
      if (!Objects.equals(this.lat, other.lat)) {
         return false;
      }
      if (!Objects.equals(this.lon, other.lon)) {
         return false;
      }
      if (!Objects.equals(this.regionName, other.regionName)) {
         return false;
      }
      return true;
   }
   
   
   @Override
   public String toString() {
      return "GeoPluginLookupDataString[ ip = " + this.ip + ", areaCode = " 
           + this.areaCode + ", city = " + this.city + ", continent = "
           + this.continentCode + ", country = " + this.countryName + " ("
           + this.countryCode + "), currency = " + this.currencyCode + " ("
           + this.currencySymbol + "), coordinates = " + this.lat + "° / "
           + this.lon + "°, region = " + this.regionName + " ]";
   }
}
